package com.ztgf.sys.api.cms;

import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.CustomizeUtil;
import com.ztgf.sys.models.bo.SysHomePageBO;
import com.ztgf.sys.models.service.ISysHomePageStatisticsService;
import com.ztgf.sys.models.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
 * @author chenyu.wang
 * @date 2020-08-07
 * @description:系统首页控制器
 */
@RestController
@RequestMapping("/cms/sysHomePageStatisticsController")
@Api(value = "SysHomePageStatisticsController", tags = "系统首页统计表接口")
public class SysHomePageStatisticsController {

    @DubboReference
    private ISysHomePageStatisticsService sysHomePageStatisticsService;

    @PostMapping(value = "/querySysHomeStatistice")
    @ApiOperation(value = "后台首页订单和待处理事项统计", notes = "后台首页订单和待处理事项统计")
    public Result<?> querySysHomeStatistice() {
        SysHomePageStatisticsVO vo = sysHomePageStatisticsService.querySysHomeStatistice();
        return new Result<>(vo);
    }

    @PostMapping(value = "/querySysHomeOverview")
    @ApiOperation(value = "后台首页商品总览和用户总览", notes = "后台首页商品总览和用户总览")
    public Result<?> querySysHomeOverview() {
        SysHomePageOverviewVO vo = sysHomePageStatisticsService.querySysHomeOverview();
        return new Result<>(vo);
    }

    @PostMapping(value = "/querySysHomePageOrderNum")
    @ApiOperation(value = "后台管理系统首页订单统计", notes = "后台管理系统首页订单统计")
    public Result<?> querySysHomePageOrderNum(SysHomePageBO bo) {
        if (CustomizeUtil.strIsNotNull(bo.getStartTime()) && CustomizeUtil.strIsNotNull(bo.getEndTime())) {
            List<SysLineChartVO> list = sysHomePageStatisticsService.querySysHomePageOrderCount(bo.getStartTime(), bo.getEndTime());
            return new Result<>(list);
        }
        return new Result<>(CodeEnum.FAIL_100002);
    }

    @PostMapping(value = "/getSysHomePageOrderLeft")
    @ApiOperation(value = "后台管理系统首页订单统计左侧对比", notes = "后台管理系统首页订单统计左侧对比")
    public Result<?> getSysHomePageOrderLeft() {
        SysHomePageOrderCompareVO orderLeft = sysHomePageStatisticsService.getSysHomePageOrderLeft();
        return new Result<>(orderLeft);
    }

    @PostMapping(value = "/querySysHomePageSalesPrice")
    @ApiOperation(value = "后台管理系统首页销售额统计树状图", notes = "后台管理系统首页销售额统计树状图")
    public Result<?> querySysHomePageSalesPrice(SysHomePageBO bo) {
        if (CustomizeUtil.strIsNotNull(bo.getStartTime()) && CustomizeUtil.strIsNotNull(bo.getEndTime())) {
            List<SysLineChartVO> list = sysHomePageStatisticsService.querySysHomePageSaleCount(bo.getStartTime(), bo.getEndTime());
            return new Result<>(list);
        }
        return new Result<>(CodeEnum.FAIL_100002);
    }

    @PostMapping(value = "/querySysHomePageDealPrice")
    @ApiOperation(value = "后台管理系统首页交易额统计树状图", notes = "后台管理系统首页交易额统计树状图")
    public Result<?> querySysHomePageDealPrice(SysHomePageBO bo) {
        if (CustomizeUtil.strIsNotNull(bo.getStartTime()) && CustomizeUtil.strIsNotNull(bo.getEndTime())) {
            List<SysLineChartVO> list = sysHomePageStatisticsService.querySysHomePageDealPrice(bo.getStartTime(), bo.getEndTime());
            return new Result<>(list);
        }
        return new Result<>(CodeEnum.FAIL_100002);
    }

    @PostMapping(value = "/getSysHomePageSalesLeft")
    @ApiOperation(value = "后台管理系统首页销售额统计左侧对比", notes = "后台管理系统首页销售额统计左侧对比")
    public Result<?> getSysHomePageSalesLeft() {
        SysHomePageSalesCompareVO salesLeft = sysHomePageStatisticsService.getSysHomePageSalesLeft();
        return new Result<>(salesLeft);
    }

    @PostMapping(value = "/querySysHomePageCommission")
    @ApiOperation(value = "后台管理系统首页佣金统计树状图", notes = "后台管理系统首页佣金统计树状图")
    public Result<?> querySysHomePageCommission(SysHomePageBO bo) {
        if (CustomizeUtil.strIsNotNull(bo.getStartTime()) && CustomizeUtil.strIsNotNull(bo.getEndTime())) {
            List<SysLineChartVO> list = sysHomePageStatisticsService.querySysHomePageCommissionCount(bo.getStartTime(), bo.getEndTime());
            return new Result<>(list);
        }
        return new Result<>(CodeEnum.FAIL_100002);
    }

    @PostMapping(value = "/getSysHomePageCommissionLeft")
    @ApiOperation(value = "后台管理系统首页佣金统计左侧对比", notes = "后台管理系统首页佣金统计左侧对比")
    public Result<?> getSysHomePageCommissionLeft() {
        SysHomePageSalesCompareVO left = sysHomePageStatisticsService.getSysHomePageCommissionLeft();
        return new Result<>(left);
    }

}
